<?php

namespace app\admin\controller\order;

use app\admin\controller\Controllers;
use app\admin\service\order\Order as OrderService;
use app\admin\model\order\Order as OrderModels;

class Order extends Controllers
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index( OrderService $service )
    {
        $get = $this->request->get();
        $this->validate($get, 'app\admin\validate\order\Order.index');
        $list = $service->indexPaginate($get);
        $this->assign([
            'get' => $get,
            'list' => $list,
            'page' => $list->render(),
            'count' => $list->total(),
            'config' => config('field.order')
        ]);
        return $this->fetch('order/order/index');
    }

    /**
     * 显示指定的资源
     *
     * @param  OrderModels $model
     * @return \think\Response
     */
    public function read(OrderModels $model)
    {
        $this->assign([
            'data' => $model
        ]);
        return $this->fetch('order/order/show');
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @param OrderService $service
     * @return \think\Response
     */
    public function delete(int $id, OrderService $service)
    {
        $this->validate(['id'=>$id], 'app\admin\validate\order\Order.delete');
        if ( $service->destory($id) ) {
            return success();
        }
        return failed('删除失败');
    }

    /**
     * 批量删除
     * @param OrderService $service
     * @return \think\Response
     */
    public function destory(OrderService $service)
    {
        $delete = $this->request->only(['ids'], 'post');
        $this->validate($delete, 'app\admin\validate\order\Order.destory');
        if ( $service->destory($delete['ids']) ) {
            return success();
        }
        return failed('删除失败');
    }

}
